package org.jumiz.javafx.client.pages.commonents;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.image.Image;
import javafx.scene.layout.*;

import java.awt.*;
import java.io.File;
import java.io.InputStream;

/**
 * 统一布局
 */
public class JumizStackPane extends StackPane implements IPaneCloneable {

    public JumizStackPane() {
//        this.setStyle("-fx-background-color: white;");
        super();
        this.initListener();
    }

    /**
     * 监听页面大小变化
     */
    private void initListener() {
        super.widthProperty().addListener((observable, oldValue, newValue) -> {
            setPrefWidth(newValue.doubleValue());
        });

        super.heightProperty().addListener((observable, oldValue, newValue) -> {
            setPrefHeight(newValue.doubleValue());
        });
    }

    public JumizStackPane withBackgroundImage(String path) {
        InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
        Image image = new Image(inputStream);
        BackgroundImage backgroundImage = new BackgroundImage(
                image,
                BackgroundRepeat.NO_REPEAT,
                BackgroundRepeat.NO_REPEAT,
                BackgroundPosition.DEFAULT,
                BackgroundSize.DEFAULT);
        this.setBackground(new Background(backgroundImage));
        return this;
    }

    @Override
    public Pane clone() {
        return null;
    }
}
